package view;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
 * This is the Main Window GUI  extends JFrame 
 * @author Tal Panika	
 */ 
public class MainWindowGUI extends AbstractGUI
{
	private ArrayList<JButton> mainWindowButtons;
	private ArrayList<String> mainWindowButtonsNames;

	private int nButtons;
	private JPanel contentPane=null;
	private JLabel wrnMessage=null;	
	
	/**
	 * This is MainWindowGUI constructor.
	 * 
	 */
	public MainWindowGUI()
	{
		super();
		this.contentPane = new JPanel();
		
	    //Main Window panel 
	    contentPane.setLayout(new FlowLayout());
	    contentPane.setOpaque(true);
	    this.setContentPane(contentPane);
	    
		  //Frame
	        this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); 
	        this.setTitle("Main Window");
		    this.setLocationRelativeTo(null); //This will center the JFrame in the middle of the screen
	        this.setLocationByPlatform(true);
	        this.setSize(300, 300);
}
	
	
	/**
	 ********************************************************************* Public Methods
	 */

	/**
	 * This method gets the names of all the buttons
	 *@return names of all buttons as appear in DB
	 */
	public ArrayList<String> getMainWindowButtonsNames()
	{
		return mainWindowButtonsNames;
	}
	
	
	/**
	 * This method sets the names of the buttons to mainWindowButtonsNames
	 *@param mainWindowButtonsNames names of all buttons as appear in DB
	 */

	public void setMainWindowButtonsNames(ArrayList<String> mainWindowButtonsNames)
	{
		//set all user buttons
		this.mainWindowButtonsNames = mainWindowButtonsNames;
	    this.nButtons =  mainWindowButtonsNames.size();
	    mainWindowButtons = new ArrayList<JButton>();
	    for(int i = 0 ; i < nButtons; i++)
	    {
	    	mainWindowButtons.add(new JButton());
	    	mainWindowButtons.get(i).setText(mainWindowButtonsNames.get(i));
	    	mainWindowButtons.get(i).setVisible(false);
	    	contentPane.add(mainWindowButtons.get(i));
	    }
	    
	    //add logout button
	    mainWindowButtons.add(new JButton());
	    mainWindowButtons.get(nButtons).setText("Log out");
	    contentPane.add(mainWindowButtons.get(nButtons++));
	}

	/**
	 * This method returns the number of buttons in MainWindowGui.
	 * @return number of buttons in MainWindowGui 
	 */
	public int getnButtons() 
	{
		return nButtons;
	}


	/**
	 * This method set new Warning message to Label.
	 * @param String
	 */
	
	public void displayWrnMessage(String msg)
	{
		wrnMessage.setText(msg);
		wrnMessage.setVisible(true);
	}
	
	
	/**
	 * Button Listeners
	 */
	
	/**
	 * This method adds action listener to Add Photo button.
	 * @param listener
	 */
	public void addButtonListener(ActionListener listener , int buttonNumber)
	{
		mainWindowButtons.get(buttonNumber-1).addActionListener(listener);
	}
	
	/**
	 * This method sets a button visible
	 * @param buttonNumber the number of the button to set visible
	 * @param visibility the visibility status true is on , false is off
	 */
	public void setButtonVisible(int buttonNumber,boolean visibility) 
	{
		mainWindowButtons.get(buttonNumber-1).setVisible(visibility);
	}

	
}
